import java.time.LocalTime;
import java.util.Random;

public class WaterTank {
    private State currentState;
    private boolean hasWater = true; // 模拟水量传感器
    private int temperature = 15;   // 当前温度
    private boolean isBurnedOut = false;
    private boolean powerOn = false;

    public WaterTank() {
        this.currentState = new UnstartedState();
        System.out.println("水箱初始化完成，当前状态：未启动");
    }

    public void setCurrentState(State state) {
        this.currentState = state;
        System.out.println("状态切换为：" + state.getClass().getSimpleName());
    }

    public void simulateTemperatureChange() {
        if (powerOn && !isBurnedOut) {
            temperature += 3; // 加热升温
            if (temperature > 100) temperature = 100;
        } else {
            temperature -= 1; // 自然冷却
            if (temperature < 0) temperature = 0;
        }
        System.out.println("当前温度：" + temperature + "°C");
    }

    public void simulateWaterLevel() {
        Random r = new Random();
        hasWater = r.nextBoolean(); // 随机有无水
    }

    public LocalTime getCurrentTime() {
        return LocalTime.now();
    }

    public void handleTemperatureBelow20AndHasWater() {currentState.onTemperatureBelow20AndHasWater(this);}
    public void handleTemperatureReached100() {currentState.onTemperatureReached100(this);}
    public void handleNoWater() {currentState.onNoWater(this);}
    public void handleBurnedOut() {currentState.onBurnedOut(this);}
    public void handleMorning7() {currentState.onMorning7(this);}
    public void handleNight11() {currentState.onNight11(this);}

    public boolean hasWater() {return hasWater;}
    public int getTemperature() {return temperature;}
    public boolean isBurnedOut() {return isBurnedOut;}
    public boolean isPowerOn() {return powerOn;}
    public void setPowerOn(boolean powerOn) {this.powerOn = powerOn;}
    public void setIsBurnedOut(boolean burnedOut) {this.isBurnedOut = burnedOut;}

    @Override
    public String toString() {
        return "WaterTank{" +
                "temperature=" + temperature +
                ", hasWater=" + hasWater +
                ", powerOn=" + powerOn +
                ", isBurnedOut=" + isBurnedOut +
                '}';
    }
}